import { Injectable } from '@nestjs/common';
import { CreateCouponInfoDto } from './dto/create-coupon_info.dto';
import { UpdateCouponInfoDto } from './dto/update-coupon_info.dto';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { CouponInfo } from './entities/coupon_info.entity';
import { Logger } from '@nestjs/common';
import { SuccessResponse } from '../../../util/ResultResponse';

@Injectable()
export class CouponInfoService {
  private readonly logger: Logger = new Logger('CouponInfoService');

  constructor(
    @InjectRepository(CouponInfo)
    private readonly couponInfoRepository: Repository<CouponInfo>,
  ) {}


  create(createCouponInfoDto: CreateCouponInfoDto) {
    return 'This action adds a new couponInfo';
  }


  async findAll():Promise<SuccessResponse<CouponInfo[]>> {
    console.log('Getting all coupons');
    return await this.couponInfoRepository.find().then((coupons) => {
      this.logger.warn(coupons)
      return {
        code: 0,
        data: coupons,
        message: '成功',
      };
    });
  }

  findOne(id: number) {
    return `This action returns a #${id} couponInfo`;
  }

  update(id: number, updateCouponInfoDto: UpdateCouponInfoDto) {
    return `This action updates a #${id} couponInfo`;
  }

  remove(id: number) {
    return `This action removes a #${id} couponInfo`;
  }
}
